package com.yunji.system.service;

import com.yunji.common.convert.NoticeConvert;
import com.yunji.common.model.domain.NoticeDO;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.model.params.NoticeParams;
import com.yunji.common.model.vo.NoticeVO;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.system.context.SystemContext;
import com.yunji.system.dao.INoticeDao;
import javafx.util.Pair;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("NoticesService")
public class NoticeService {

    @Resource
    private INoticeDao noticeDao;

    public Long save(NoticeDO notice) {
        noticeDao.save(notice);
        return notice.getNoticeId();
    }

    public List<NoticeVO> pageList(NoticeParams params) {
        LoginInfo user = SystemContext.getUser();
        BeanUtils.clone(user,params);
        List<NoticeDO> list = noticeDao.getPageList(params);
        return NoticeConvert.DOToVO(list);
    }

    public Map<String, Object> getInfo(Long id) {
        return NoticeConvert.JsonToMap(noticeDao.getById(id).getNoticeContent());
    }

}
